<!DOCTYPE html>
<html lang="zh_CN">
<head>
  <% include("/include/header3.html",{"title":"首页"}){} %>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
  <!-- 头部 -->
  <div class="layui-header">
    <div class="layui-logo">
      <img src="${app.logo!'images/logo.png'}"/>
      <cite>&nbsp;${app.title!'小作坊管理系统'}</cite>
    </div>
    <ul class="layui-nav layui-layout-left" id="wbh-nav-top-box">
      <li class="layui-nav-item" lay-unselect>
        <a ew-event="flexible" title="侧边伸缩"><i class="layui-icon layui-icon-shrink-right"></i></a>
      </li>
      <li class="layui-nav-item" lay-unselect>
        <a ew-event="refresh" title="刷新"><i class="layui-icon layui-icon-refresh-3"></i></a>
      </li>
    </ul>
    <ul class="layui-nav layui-layout-right">
      <li class="layui-nav-item relative" lay-unselect>
        <a ew-href="dev/messageUser/index" ew-title="站内信" ew-event="onMessage" title="消息">
          <i class="layui-icon layui-icon-notice"></i>
          <span id="badgeDot" class="layui-badge layui-hide round-20" style="top:20%;margin: -3px -10px 0"></span>
        </a>
      </li>
      <li class="layui-nav-item" lay-unselect>
        <a data-url="/other/note" ew-event="note" title="便签"><i class="layui-icon layui-icon-note"></i></a>
      </li>
      <li class="layui-nav-item layui-hide-xs" lay-unselect>
        <a ew-event="fullScreen" title="全屏"><i class="layui-icon layui-icon-screen-full"></i></a>
      </li>
      <!--<li class="layui-nav-item layui-hide-xs" lay-unselect>
        <a data-url="/other/lockScreen" ew-event="lockScreen" title="锁屏"><i class="layui-icon layui-icon-password"></i></a>
      </li>-->
      <li class="layui-nav-item" lay-unselect>
        <a>
          <img class="layui-nav-img" src="${avatar!''}"/>
          <cite>${name!'TODO'}</cite>
        </a>
        <dl class="layui-nav-child">
          <dd lay-unselect><a ew-href="/other/userInfo">个人中心</a></dd>
          <dd lay-unselect><a data-url="/other/updatePassword" ew-event="psw">修改密码</a></dd>
          <hr/>
          <dd lay-unselect><a data-url="/logout" ew-event="logout">退出</a></dd>
        </dl>
      </li>
      <li class="layui-nav-item" lay-unselect>
        <a data-url="other/theme" ew-event="theme" title="主题"><i class="layui-icon layui-icon-more-vertical"></i></a>
      </li>
    </ul>
  </div>

  <!-- 侧边栏 -->
  <div class="layui-side">
    <div class="layui-side-scroll"></div>
  </div>

  <!-- 主体部分 -->
  <div class="layui-body"></div>
  <!-- 底部 -->
  <div class="layui-footer layui-text">
    ${app.copyright!'copyright © 2023 <a href="http://wangbuhao.org" target="_blank">鸡泽县瑾瑜软件开发工作室</a> all rights reserved.'}
    <span class="pull-right">${app.version!'小作坊 1.0.0'}</span>
  </div>
</div>

<!-- 加载动画 -->
<div class="page-loading" id="page-loading">
  <div class="ball-loader"><span></span><span></span><span></span><span></span></div>
</div>

<!-- 侧边栏渲染模板 -->
<script id="sideNav" type="text/html">
  {{# layui.each(d, function(index, item){ }} {{# if(index === 0){ }}
  <ul class="layui-nav layui-nav-tree" lay-shrink="_all" lay-filter="admin-side-nav" nav-id="{{item.code}}" style="margin: 15px 0;">
    {{# layui.each(item.value, function(index, menuItem){ }}
    <li class="layui-nav-item">
      <a lay-href="{{menuItem.value}}"><i class="layui-icon {{menuItem.icon}}"></i>&emsp;<cite>{{ menuItem.title }}</cite></a>
      {{# if(menuItem.children&&menuItem.children.length>0){ getSubMenus(menuItem.children); } }}
    </li>
    {{# }); }}
  </ul>{{# } else { }}
  <ul class="layui-nav layui-nav-tree layui-hide" lay-shrink="_all" lay-filter="admin-side-nav" nav-id="{{item.code}}" style="margin: 15px 0;">
    {{# layui.each(item.value, function(index, menuItem){ }}
    <li class="layui-nav-item">
      <a lay-href="{{menuItem.value}}"><i class="layui-icon {{menuItem.icon}}"></i>&emsp;<cite>{{ menuItem.title }}</cite></a>
      {{# if(menuItem.children&&menuItem.children.length>0){ getSubMenus(menuItem.children); } }}
    </li>
    {{# }); }}
  </ul>{{# } }} {{# }); }} {{# function getSubMenus(children){ }}
  <dl class="layui-nav-child">
    {{# layui.each(children, function(index, subItem){ }}
    <dd>
      <a lay-href="{{ subItem.value }}">{{ subItem.title }}</a>
      {{# if(subItem.children&&subItem.children.length>0){ getSubMenus(subItem.children); } }}
    </dd>
    {{# }); }}
  </dl>{{# } }}
</script>

<!-- 顶部系统栏渲染模板 -->
<script id="topNav" type="text/html">
  {{# layui.each(d, function(index, item){ }} {{# if(index === 0 && item.active === 1){ }}
  <li class="layui-nav-item layui-hide-xs layui-this" lay-unselect><a nav-bind="{{item.code}}">{{ item.name }}</a></li>{{# } else { }}
  <li class="layui-nav-item layui-hide-xs" lay-unselect><a nav-bind="{{item.code}}"> {{item.name}} </a></li>{{# } }} {{# }); }}
  <!-- 小屏幕下变为下拉形式 -->
  <li class="layui-nav-item layui-hide-sm layui-show-xs-inline-block" lay-unselect>
    <a>更多</a>
    <dl class="layui-nav-child" id="nav-sm">
      {{# layui.each(d, function(index, item){ }}
      <dd lay-unselect><a nav-bind="{{item.code}}"> {{item.name}} </a></dd>
      {{# }); }}
    </dl>
  </li>
</script>

<!-- js部分 -->
<script>
  layui.use(["element", "admin", "index", "laytpl"], function () {
    var $ = layui.jquery;
    var admin = layui.admin;
    var index = layui.index;
    var laytpl = layui.laytpl;
    var element = layui.element;

    // ajax渲染侧边栏
    req(axiosGet, "user/menu", {}, function (res) {
      if (res.code === 200) {
        //渲染顶部系统栏
        laytpl(topNav.innerHTML).render(res.data.apps, function (html) {
          $("#wbh-nav-top-box").append(html);
        });

        //渲染左侧菜单
        laytpl(sideNav.innerHTML).render(res.data.menus, function (html) {
          $(".layui-side-scroll").html(html);
          element.render("nav");
          // 加载页面
          index.loadHome({
            menuPath: "home/welcome",
            menuName: '<i class="layui-icon layui-icon-home"></i>',
            // 刷新后默认打开上次的页签
            loadSetting: false,
            // 并且只打开最后一个页签
            onlyLast: true,
          });

        });
      } else {
        $base.removeLoading();
        $baseAlert(res.msg);
      }
    });


    // 是否有消息
    const getUnRead = () => {
      req(axiosGet, "dev/messageUser/unReadCount", {}, function (res) {
        if (res.code === 200 && res.data.count > 0) {
          const count = res.data.count;
          $('#badgeDot').removeClass("layui-hide");
          $('#badgeDot').text(count > 99 ? '99+' : count);
        }
      })
    }

    // 定时器 复杂的可以做通讯
    getUnRead();
    setInterval(getUnRead, 1000 * 30);

    // admin.events.onMessage = () => {
    //   openLayer({
    //     title: "通知消息",
    //     content: "dev/messageUser/message",
    //     area: ['80%', '90%'],
    //   })
    // }

    admin.events.logout = () => {
      $baseConfirm("确定退出本系统吗?", () => {
        admin.req(BASEURL + 'anon/logout', {}, function () {
          window.location.reload()
        }, 'delete');
      })
    }


  });
</script>
</body>
</html>
